documentation. */
Lisp_Object Vfunction_key_map;
-Lisp_Object Qkeymapp, Qkeymap;
+Lisp_Object Qkeymapp, Qkeymap, Qnon_ascii;
/* A char over 0200 in a key sequence
is equivalent to prefixing with this character. */
return build_string (tem);
}
+
+/* Return non-zero if SEQ contains only ASCII characters, perhaps with
+ a meta bit. */
+static int
+ascii_sequence_p (seq)
+ Lisp_Object seq;
+{
+ Lisp_Object i;
+ int len = XINT (Flength (seq));
+
+ for (XFASTINT (i) = 0; XFASTINT (i) < len; XFASTINT (i)++)
+ {
+ Lisp_Object elt = Faref (seq, i);
+
+ if (XTYPE (elt) != Lisp_Int
+ || (XUINT (elt) & ~CHAR_META) >= 0x80)
+ return 0;
+ }
+
+ return 1;
+}
+
\f
/* where-is - finding a command in a set of keymaps. */
If KEYMAP is nil, search only KEYMAP1.\n\
If KEYMAP1 is nil, use the current global map.\n\
\n\
-If optional 4th arg FIRSTONLY is non-nil,\n\
-return a string representing the first key sequence found,\n\
-rather than a list of all possible key sequences.\n\
+If optional 4th arg FIRSTONLY is non-nil, return a string representing\n\
+the first key sequence found, rather than a list of all possible key\n\
+sequences. If FIRSTONLY is t, avoid key sequences which use non-ASCII\n\
+keys and therefore may not be usable on ASCII terminals. If FIRSTONLY\n\
+is the symbol `non-ascii', return the first binding found, no matter\n\
+what its components.\n\
\n\
If optional 5th arg NOINDIRECT is non-nil, don't follow indirections\n\
to other keymaps or slots. This makes it possible to search for an\n\
}
/* It is a true unshadowed match. Record it. */
+ found = Fcons (sequence, found);
- if (!NILP (firstonly))
+ /* If firstonly is Qnon_ascii, then we can return the first
+ binding we find. If firstonly is not Qnon_ascii but not
+ nil, then we should return the first ascii-only binding
+ we find. */
+ if (EQ (firstonly, Qnon_ascii))
+ return sequence;
+ else if (! NILP (firstonly) && ascii_sequence_p (sequence))
return sequence;
- found = Fcons (sequence, found);
}
}
- return Fnreverse (found);
+
+ found = Fnreverse (found);
+
+ /* firstonly may have been t, but we may have gone all the way through
+ the keymaps without finding an all-ASCII key sequence. So just
+ return the best we could find. */
+ if (! NILP (firstonly))
+ return Fcar (found);
+
+ return found;
}
/* Return a string listing the keys and buttons that run DEFINITION. */
Qkeymapp = intern ("keymapp");
staticpro (&Qkeymapp);
+ Qnon_ascii = intern ("non-ascii");
+ staticpro (&Qnon_ascii);
+
defsubr (&Skeymapp);
defsubr (&Smake_keymap);
defsubr (&Smake_sparse_keymap);